// TabButton.cpp : implementation file
//

#include "stdafx.h"
#include "TabButton.h"
#include "resource.h"
#include <commondef/glb_msg_define.h>

// CTabButton

IMPLEMENT_DYNAMIC(CTabButton, CButton)

CTabButton::CTabButton()
{
	m_btnID  = -1;
}

CTabButton::~CTabButton()
{
}


BEGIN_MESSAGE_MAP(CTabButton, CButton)
	ON_WM_SIZE()
END_MESSAGE_MAP()



// CTabButton message handlers

void CTabButton::CreateChildButton(int nID, const CRect &rtMargin)
{

	CRect rtThis;
	GetClientRect( &rtThis);

	CRect r_child;
	r_child.left = rtThis.right - 16;
	r_child.top = rtThis.top + 1;
	r_child.bottom = rtThis.bottom -1;
	r_child.right = rtThis.right;
	m_childBtn.Create(_T(""), WS_CHILD|BS_PUSHBUTTON|WS_VISIBLE, r_child, this, nID);
	dsSkinWindow( m_childBtn.GetSafeHwnd(), SKIN_TYPE_BUTTON, _T("imchat_tab_menu"), FALSE);
	m_btnID = nID;
	m_rtbtnMargin = rtMargin;
}


void CTabButton::OnSize(UINT nType, int cx, int cy)
{
	CButton::OnSize(nType, cx, cy);

	if ( ::IsWindow( m_childBtn.GetSafeHwnd()))
	{
		CRect rtThis;
		GetClientRect( &rtThis);
		CRect r_child;
		r_child.left = rtThis.right - 16;
		r_child.top = rtThis.top + 1;
		r_child.bottom = rtThis.bottom -1;
		r_child.right = rtThis.right;
		m_childBtn.MoveWindow( &r_child, TRUE);
	}
}

void CTabButton::ShowChildButton(BOOL bShow)
{
	if ( bShow )
	{
		m_childBtn.ShowWindow( SW_SHOW);
	}
	else
	{
		m_childBtn.ShowWindow( SW_HIDE);
	}
}


BOOL CTabButton::OnCommand(WPARAM wParam, LPARAM lParam)
{
	CRect rect;
	m_childBtn.GetWindowRect( &rect);
	LPARAM lParam1 = MAKELPARAM( rect.left, rect.bottom);
	GetParent()->PostMessage(  WM_GLB_UI_MAIN_TAB_MENU_BTN_CLICK, m_btnID, lParam1);

	return CButton::OnCommand(wParam, lParam);
}

/// basic check by fan05
BOOL CTabButton::PreTranslateMessage(MSG* pMsg)
{
	// TODO: Add your specialized code here and/or call the base class

	return CButton::PreTranslateMessage(pMsg);
}
